package base_Suanfa.dongtaiguihua;

public class beibao_wenti {
    public static void main(String[] args) {
        int[] weight = {1, 4, 3};
        //各个物品的价值
        int[] value = {1500, 3000, 2000};
        //背包的最大容量
        int maxSize = 4;
        int max=0;
        int a[][]=new int[weight.length+1][maxSize+1];
        for(int i=1;i<weight.length+1;i++){
            for(int j=1;j<maxSize+1;j++){
                if(weight[i-1]>j){
                    a[i][j]=a[i-1][j];
                }
                else {
                    a[i][j]=Math.max(a[i-1][j],a[i-1][j-weight[i-1]]+value[i-1]);
                }
            }
        }
        for(int i=0;i<weight.length+1;i++){
            for(int j=0;j<maxSize+1;j++){
                System.out.print(a[i][j]+" ");
            }
            System.out.println();
        }
    }
}
